<?php
/**
 * @author shutyuka@gmail.com
 * @modified 2011-02-20
 */
class Campaign{
	
	static public $FLAG_INACTIVE = 0;
	
	static public $FLAG_UNACTIVE = 10;
	
	static public $TABLE_NAME="campaigns";

	static public function Create($campaign) {
		$campaign['create_time'] = time();
		$campaign['id'] = DB::Insert(self::$TABLE_NAME, $campaign);
		
		return $campaign['id'];
	}
	
	static public function Update($campaign) {
		Table::UpdateCache(self::$TABLE_NAME, $campaign['id'], $campaign);
		
		return ;
	}
	
	static public function GetAll(){
		$oc = array( 
			'activity' => self::$FLAG_INACTIVE
			);
		$allShops = DB::LimitQuery(self::$TABLE_NAME, array(
				'condition' => $oc,
				'order' => 'ORDER BY id ASC'
				));
		return $allShops;
	}
	
static public function GetAllByShopId($shopId){
		$oc = array( 
			'activity' => self::$FLAG_INACTIVE,
			'shop_id' => $shopId
			);
		$allShops = DB::LimitQuery(self::$TABLE_NAME, array(
				'condition' => $oc,
				'order' => 'ORDER BY id ASC'
				));
		return $allShops;
	}

	static public function SetCampaignUnactive($campaignId) {
		if (!$campaignId) 
			return array();
		Table::UpdateCache(self::$TABLE_NAME, $campaignId, array(
			'activity' => self::$FLAG_UNACTIVE)
		);
		return ;
	}
	
	
	static public function SetCampaignInActive($campaignId) {
		if (!$campaignId) 
			return array();
		Table::UpdateCache(self::$TABLE_NAME, $campaignId, array(
			'activity' => self::$FLAG_INACTIVE)
		);
		return ;
	}
	
	static public function getById($id){
		$shop = DB::GetTableRow(self::$TABLE_NAME, array(
					'id' => $id,
		));
		return $shop;
	}
	
}
